from common.utils.rights import permission_required, view_logging_required
from common.utils.file_read import file_read
from . import index_bp
from flask import render_template,request
from flask_wtf.form import CombinedMultiDict
from models.form import UploadForm
import cv2 as cv
import numpy as np



@index_bp.get('/zoom_pro')
@index_bp.post('/zoom_pro')
@view_logging_required
@permission_required("zoom:pro")
def zoom_pro():
    if request.method == "GET":
        return render_template('admin/cv/zoom.html')
    else:
        form = UploadForm(CombinedMultiDict([request.form, request.files]))
        if form.validate():
            f = request.files['file']
            width = request.form.get('width')
            height = request.form.get('height')
            file_url = file_read(f)
            pic = cv.imread(file_url)
            res_pic = "static/download/zoom.jpg"
            out_image = cv.resize(pic, (int(width), int(height)))
            cv.imwrite(res_pic, out_image)
            return render_template('admin/cv/zoom.html', pic=file_url, res_pic=res_pic)
        else:
            return "请传入正确的文件格式"
